package com.zhangln.mountbuzhou.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhangln.mountbuzhou.dao.TbOnlineDao;
import com.zhangln.mountbuzhou.dao.TbPushLogDao;
import com.zhangln.mountbuzhou.dto.BaseResponse;
import com.zhangln.mountbuzhou.entity.TbOnlineEntity;
import com.zhangln.mountbuzhou.entity.TbPushLogEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 当前在线设备 前端控制器
 * </p>
 *
 * @author sherry
 * @since 2020-04-27
 */
@RestController
@RequestMapping("/reg")
public class TbOnlineController {

    @Value("${buzhou.timeout}")
    private Integer timeout;

    private final TbOnlineDao tbOnlineDao;

    public TbOnlineController(TbOnlineDao tbOnlineDao) {
        this.tbOnlineDao = tbOnlineDao;
    }

    /**
     * 主动下线服务
     *
     * @return
     */
    @PostMapping("/offline")
    public BaseResponse offlineTimeoutDev() {

//        下线超过10分钟的设备
        tbOnlineDao.remove(new QueryWrapper<TbOnlineEntity>()
                .le(TbOnlineEntity.UPDATED_TIME, LocalDateTime.now().minusMinutes(timeout)));
        return BaseResponse.builder().build();
    }
}

